home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bbsess.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-01-11  |  4.8 KB  |  187 lines

  1. (*===========================================================================*)
  2. (* Session services                                                          *)
  3. (*                                                                           *)
  4. (*   Copyright 1988, 1989, 1990, 1991 by H. Roy Engehausen.  All rights      *)
  5. (*   reserved.                                                               *)
  6. (*                                                                           *)
  7. (*===========================================================================*)
  8.  
  9. UNIT BBSESS;
  10.  
  11. INTERFACE
  12.  
  13.   USES
  14.     bbdummy;
  15.  
  16.   PROCEDURE end_session(add_delay : BOOLEAN);
  17.   PROCEDURE timer_end_session;
  18.   PROCEDURE task_wait (seconds_to_wait : WORD; poll_during_wait : BOOLEAN);
  19.   PROCEDURE cmd_tnc(cmd_string : str_ptr; display_switch : BOOLEAN);
  20.  
  21. IMPLEMENTATION
  22.  
  23.   USES
  24.     bblstr,
  25.     bbmdata,
  26.     bbmess,
  27.     bbmisc,
  28.     bbrdata,
  29.     bbsdata,
  30.     bbsrt,
  31.     bbtask,
  32.     bbtime,
  33.     bbwin;
  34.  
  35. (*===========================================================================*)
  36. (* Command TNC                                                               *)
  37. (*===========================================================================*)
  38.  
  39. PROCEDURE cmd_tnc(cmd_string : str_ptr; display_switch : BOOLEAN);
  40.  
  41.   VAR
  42.     t_str  : STRING[4];
  43.  
  44.   BEGIN;
  45.  
  46.     {$IFDEF DEBUG_1}
  47.       WRITELN('Command TNC -- ', cmd_string^);
  48.       DELAY(1000);
  49.     {$ENDIF}
  50.  
  51.     WITH active_tcb^ DO
  52.       BEGIN;
  53.  
  54.         {$IFDEF DEBUG_1}
  55.           WRITELN('Command TNC -- #2 -- ', LENGTH(cmd_string^));
  56.           DELAY(1000);
  57.         {$ENDIF}
  58.  
  59.         IF display_switch THEN
  60.           BEGIN;
  61.             t_str := port_chan_s + '^:';
  62.             window_write(t_str, cmd_string^);
  63.           END;
  64.  
  65.         {$IFDEF DEBUG_1}
  66.           WRITELN('Long move');
  67.           DELAY(1000);
  68.         {$ENDIF}
  69.  
  70.         l_move_str(@tnc_data, cmd_string^);
  71.  
  72.         {$IFDEF DEBUG_1}
  73.           WRITELN('Command TNC -- ', tnc_data.long_length);
  74.           DELAY(1000);
  75.         {$ENDIF}
  76.  
  77.  
  78.         IF tnc_data.long_length = 0 THEN
  79.           tnc_null := TRUE
  80.         ELSE
  81.           send_recv_tnc(info_cmd_cmd);
  82.  
  83.         IF display_switch THEN
  84.           BEGIN;
  85.             t_str[3] := '-';
  86.             IF (tnc_data.long_length > 0) THEN
  87.               window_write(t_str, tnc_data.str_data)
  88.             ELSE
  89.               window_write(t_str, 'OK');
  90.           END;
  91.  
  92.       END;
  93.  
  94.   END;
  95.  
  96. (*===========================================================================*)
  97. (* End a session -- There is no exit from this.....                          *)
  98. (*===========================================================================*)
  99.  
  100. PROCEDURE end_session(add_delay : BOOLEAN);
  101.  
  102.   VAR
  103.     t : LONGINT;
  104.  
  105.   BEGIN;
  106.  
  107.     send_drain;
  108.  
  109.     IF add_delay THEN
  110.       task_wait(active_port^.disc_delay, TRUE);
  111.  
  112.     cmd_tnc(@disc_cmd, TRUE);
  113.  
  114.     WITH active_tcb^ DO
  115.       IF NOT tnc_null THEN
  116.         BEGIN;
  117.           active_port^.connected^[channel] := NIL;
  118.           task_destroy_active;
  119.         END;
  120.  
  121.     WITH active_tcb^ DO
  122.       IF (window = window_operator) AND NOT tcb_ignore_lc THEN
  123.         window := window_connect;
  124.  
  125.     t := time_from_now(600);
  126.  
  127.     WHILE t > current_day_time DO
  128.       BEGIN;
  129.         read_flush;
  130.         task_switch;
  131.       END;
  132.  
  133.     window_write_critical(active_tcb^.port_chan_s + 'D:',
  134.                           'Forcing disconnected task after wait');
  135.     task_destroy_active;
  136.  
  137.   END;
  138.  
  139. (*===========================================================================*)
  140. (* End a session -- Timeout                                                  *)
  141. (*===========================================================================*)
  142.  
  143. PROCEDURE timer_end_session;
  144.  
  145.   BEGIN;
  146.  
  147.     (*-----------------------------------------------------------------------*)
  148.     (* Time expired.  Tell user then dump the connection.                    *)
  149.     (*-----------------------------------------------------------------------*)
  150.  
  151.     send_message(message_to_noact);
  152.     send_flush;
  153.  
  154.     WHILE send_unacked(TRUE) > 0 DO
  155.       BEGIN;
  156.         task_switch;
  157.         read_flush;
  158.       END;
  159.  
  160.     end_session(TRUE);
  161.  
  162.   END;
  163.  
  164. (*===========================================================================*)
  165. (* task wait                                                                 *)
  166. (*===========================================================================*)
  167.  
  168. PROCEDURE task_wait(seconds_to_wait : WORD; poll_during_wait : BOOLEAN);
  169.  
  170.   VAR
  171.     i               : BYTE;
  172.     wait_until_time : LONGINT;
  173.  
  174.   BEGIN;
  175.  
  176.     wait_until_time := up_time_from_now(seconds_to_wait);
  177.  
  178.     REPEAT;
  179.       task_switch;
  180.       IF poll_during_wait THEN
  181.         i := send_pending(FALSE);
  182.     UNTIL (wait_until_time <= up_time);
  183.  
  184.   END;
  185.  
  186. END.
  187.